package com.spboot.controller;


import com.spboot.entity.User;
import com.spboot.service.IUserService;
import com.spboot.util.PageInfo;
import com.spboot.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.UUID;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author guocb
 * @since 2021-03-25
 */
@CrossOrigin //支持跨域
@RestController //Ajax
@RequestMapping("/user")
public class UserController {


    @Autowired
    IUserService userService;

    @RequestMapping("/page")
    private Result page(@RequestParam(defaultValue = "1", required = false) Integer pageno) {
        PageInfo<User> pageInfo = new PageInfo<>(pageno, 10);
        pageInfo = userService.page(pageInfo);
        return Result.ok(pageInfo);
    }

    @RequestMapping("/get")
    public Result get(Integer id) {
        return Result.ok(userService.getById(id));
    }

    @RequestMapping("/save")
    public Result save(@RequestBody User user) {
        return Result.ok(userService.saveOrUpdate(user));
    }

    @RequestMapping("/del")
    public Result del(Integer id) {
        return Result.ok(userService.removeById(id));
    }

}
